import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:magic_car/common/nodata.dart';
import 'package:magic_car/res/colors.dart';
import 'package:magic_car/util/HttpHelper.dart';
import 'package:shared_preferences/shared_preferences.dart';
//子页面
class MileAgePage extends StatefulWidget {
 final String queryid;

  MileAgePage(this.queryid);

  @override
  _ChildItemViewState createState() => _ChildItemViewState();
}

class _ChildItemViewState extends State<MileAgePage> {
  List codelist=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getqueryinfo();

  }
  getqueryinfo() async{
     EasyLoading.show(status: "正在查询");
    Map<String, String> param = new Map();
    SharedPreferences pref = await SharedPreferences.getInstance();
    param["uid"] = pref.getString('uid');
    param['id'] = widget.queryid;
  
    HttpHelper.post(HttpHelper.API_QueryHistoryinfo, (data) async {
      EasyLoading.dismiss();
      if (data != null) {
        for (var item in  data['info']['problem']) {
          codelist.add(item);
        }
        setState(() {
          codelist = codelist;
        });
      }
    
    }, params: param);
  }
  @override
  Widget build(BuildContext context) {
    return
    Scaffold(appBar:
    new AppBar(title: Text("历史里程"),backgroundColor: Colors.white,elevation: 0,)
     ,body:
     Container(
       child:codelist.length==0?Nodata(): new ListView.builder(itemBuilder: (BuildContext context,int index){
        return new Container(
          color: Colors.white,
          margin: new EdgeInsets.only(bottom: 1),
          // margin: new EdgeInsets.all(10),
          padding: new EdgeInsets.fromLTRB(30, 10, 30, 10),
          child: Row(
            mainAxisAlignment:MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children:
            index==0?
             [
               Container(child:
              Text("查询时间",style: TextStyle(color:Colors.black87,fontSize: 15),)),
              // Container(width: 100,),
              Container(child:
               Text("里程(公里)",style: TextStyle(color: Colors.black87,fontSize: 15),)),
             
]:
             [
               Container(child:
              Text(codelist[index-1]["updateTime"],style: TextStyle(color:Colors.black87,fontSize: 13),)),
              // Container(width: 100,),
              Container(child:
               Text(codelist[index-1]["mileage"],style: TextStyle(color: Colors.black87,fontSize: 15),)),
             

            ],
          ),
        );
       },itemCount: codelist.length+1,)),
     
    );
    
  }
}